package com.museum.controller;


import com.alibaba.fastjson.JSONObject;
import com.museum.base.BaseApiService;
import com.museum.base.BaseResponse;
import com.museum.controller.APi.InputApplyAPI;
import com.museum.entity.DO.InputApply;
import com.museum.service.impl.InputApplyServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Ahm
 * @since 2021-03-15
 */
@RestController
@RequestMapping("/input-apply")
public class InputApplyController extends BaseApiService<JSONObject> implements InputApplyAPI {

    @Autowired
    private InputApplyServiceImpl applyService;

    @Override
    public BaseResponse<JSONObject> addInputApply(InputApply inputApply, HttpServletRequest request) {

        int result = applyService.addInputApply(inputApply, request);
        if (result>0){
            return setResultSuccess("申请成功");
        }else {
            return setResultError("申请失败");
        }
    }

    @Override
    public BaseResponse<JSONObject> getAllApplyByPage(long current, long limit, InputApply inputApply) {
        JSONObject json = applyService.getAllInputApplyByPage(current, limit, inputApply);
        return setResultSuccess(json);
    }

    @Override
    public BaseResponse<JSONObject> getApplyById(Integer id) {
        JSONObject json = applyService.getApplyById(id);
        return setResultSuccess(json);
    }

    @Override
    public BaseResponse<JSONObject> selectApplyCheckByPage(long current, long limit, InputApply inputApply) {
        JSONObject json = applyService.getAllInputCheckByPage(current,limit,inputApply);
        return setResultSuccess(json);
    }

    @Override
    public BaseResponse<JSONObject> agreeCheckById(Integer id) {
        int result = applyService.updateCheckById(id);
        if (result>0){
            return setResultSuccess("审核成功");
        }else {
            return setResultError("审核失败");
        }
    }

    @Override
    public BaseResponse<JSONObject> disagreeCheckById(Integer id) {
        int result = applyService.disagreeCheckById(id);
        if (result>0){
            return setResultSuccess("审核成功");
        }else {
            return setResultError("审核失败");
        }
    }

    @Override
    public BaseResponse<JSONObject> fileById(Integer id) {
        int result = applyService.fileById(id);
        if (result>0){
            return setResultSuccess("归档成功");
        }else {
            return setResultError("归档失败");
        }

    }

    @Override
    public BaseResponse<JSONObject> selectInputDealByPage(long current, long limit, InputApply inputApply) {
        JSONObject json = applyService.getAllInputDealByPage(current,limit,inputApply);
        return setResultSuccess(json);
    }

    @Override
    public BaseResponse<JSONObject> selectFileByPage(long current, long limit, InputApply inputApply) {
        JSONObject json = applyService.getFileByPage(current,limit,inputApply);
        return setResultSuccess(json);
    }

}

